<template>
  <div class="app-container">
    <!-- 搜索区域：按实体类顺序排列核心字段 -->
    <el-form
        :model="queryParams"
        ref="queryRef"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
    >
      <!-- 核心搜索项：默认展示 -->
      <el-form-item label="类型" prop="stuType">

          <el-select
                v-model="queryParams.stuType"
                placeholder="请选择类型"
                clearable
                @change="handleQuery"
                style="width: 180px"
             >
             <el-option
                  v-for="dict in sys_student_admission_type"
                   :key="dict.value"
                  :label="dict.label"
                   :value="dict.value"
               />
           </el-select>
      </el-form-item>

      <el-form-item label="考生编号" prop="ksbh">
        <el-input
            v-model="queryParams.ksbh"
            placeholder="请输入考生编号"
            clearable
            @keyup.enter="handleQuery"
            style="width: 180px"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="xm">
        <el-input
            v-model="queryParams.xm"
            placeholder="请输入姓名"
            clearable
            @keyup.enter="handleQuery"
            style="width: 180px"
        />
      </el-form-item>
      <el-form-item label="学号" prop="xh">
        <el-input
            v-model="queryParams.xh"
            placeholder="请输入学号"
            clearable
            @keyup.enter="handleQuery"
            style="width: 180px"
        />
      </el-form-item>
      <el-form-item label="证件类型" prop="zjlx" class="form-item">
        <el-select v-model="queryParams.zjlx" placeholder="请选择证件类型" filterable class="form-control">
          <el-option
              v-for="item in certificateTypeList"
              :key="item.cardtValue"
              :label="item.cardtLabel"
              :value="item.cardtValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="身份证号" prop="zjhm">
        <el-input
            v-model="queryParams.zjhm"
            placeholder="请输入身份证号"
            clearable
            @keyup.enter="handleQuery"
            style="width: 220px"
        />
      </el-form-item>
      <el-form-item label="导入状态" prop="drzt">
        <el-select
            v-model="queryParams.drzt"
            placeholder="请选择导入状态"
            filterable
            style="width: 200px"
        >
          <el-option
              v-for="dict in rxdrzt"
              :key="dict.id"
              :label="dict.label"
              :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <!-- 次要搜索项：折叠展示，按实体类顺序 -->
      <el-collapse v-model="activeSearchNames" class="search-collapse">
        <el-collapse-item name="more" title="更多搜索条件">
          <el-form-item label="出生日期" prop="csrq">
            <el-date-picker
                clearable
                v-model="queryParams.csrq"
                type="date"
                value-format="yyyyMMdd"
                placeholder="选择出生日期"
                style="width: 200px"
            />
          </el-form-item>
<!--          <el-form-item label="民族码" prop="mzm">-->
<!--            <el-input-->
<!--                v-model="queryParams.mzm"-->
<!--                placeholder="请输入民族码"-->
<!--                clearable-->
<!--                @keyup.enter="handleQuery"-->
<!--                style="width: 150px"-->
<!--            />-->
<!--          </el-form-item>-->
          <el-form-item label="民族" prop="mzm" class="form-item">
            <el-select v-model="queryParams.mzm" placeholder="请选择民族" filterable class="form-control">
              <el-option
                  v-for="item in nationList"
                  :key="item.nadictValue"
                  :label="item.nadictLabel"
                  :value="item.nadictValue"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="性别" prop="xbm" class="form-item">
              <el-select
                  v-model="queryParams.xbm"
                  placeholder="请选择性别"
                  filterable
                  style="width: 200px"
              >
                <el-option
                    v-for="dict in sys_user_sex"
                    :key="dict.id"
                    :label="dict.label"
                    :value="dict.value"
                />
              </el-select>
          </el-form-item>

<!--          <el-form-item label="政治面貌码" prop="zzmmm">-->
<!--            <el-input-->
<!--                v-model="queryParams.zzmmm"-->
<!--                placeholder="请输入政治面貌码"-->
<!--                clearable-->
<!--                @keyup.enter="handleQuery"-->
<!--                style="width: 150px"-->
<!--            />-->
<!--          </el-form-item>-->

          <el-form-item label="政治面貌" prop="zzmmm" class="form-item">
            <el-select v-model="queryParams.zzmmm" placeholder="请选择政治面貌" filterable class="form-control">
              <el-option
                  v-for="item in politicalStatusList"
                  :key="item.politicalValue"
                  :label="item.politicalLabel"
                  :value="item.politicalValue"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="毕业单位" prop="bydw">
            <el-input
                v-model="queryParams.bydw"
                placeholder="请输入毕业单位"
                clearable
                @keyup.enter="handleQuery"
                style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="录取专业名称" prop="lqzymc">
            <el-input
                v-model="queryParams.lqzymc"
                placeholder="请输入录取专业名称"
                clearable
                @keyup.enter="handleQuery"
                style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="毕业年月" prop="byny">
            <el-date-picker
                clearable
                v-model="queryParams.byny"
                type="month"
                value-format="yyyyMM"
                placeholder="选择毕业年月"
                style="width: 200px"
            />
          </el-form-item>
          <el-form-item label="学生资格状态" prop="xszgzc">
              <el-select
                    v-model="queryParams.xszgzc"
                    placeholder="请选择学生资格状态"
                    clearable
                    @change="handleQuery"
                    style="width: 200px"
                >
                <el-option
                      v-for="dict in sys_student_qualification_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                />
              </el-select>
          </el-form-item>

          <el-form-item label="退出现役证编号" prop="tcxyzbh">
            <el-input
                v-model="queryParams.tcxyzbh"
                placeholder="请输入退出现役证编号"
                clearable
                @keyup.enter="handleQuery"
                style="width: 200px"
            />
          </el-form-item>
        </el-collapse-item>
      </el-collapse>

      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作按钮区 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="Plus"
            @click="handleAdd"
            v-hasPermi="['student:import:add']"
            class="btn-hover-effect"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="success"
            plain
            icon="Edit"
            :disabled="single"
            @click="handleUpdate"
            v-hasPermi="['student:import:edit']"
            class="btn-hover-effect"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="danger"
            plain
            icon="Delete"
            :disabled="multiple"
            @click="handleDelete"
            v-hasPermi="['student:import:remove']"
            class="btn-hover-effect"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['student:import:export']"
            class="btn-hover-effect"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="Upload"
            @click="handleExcelImport"
            class="btn-hover-effect"
        >导入</el-button>
      </el-col>
      <el-col :span="2">
        <el-button
            type="info"
            plain
            @click="showAllColumns = !showAllColumns"
            class="btn-hover-effect"
        >
          {{ showAllColumns ? '隐藏次要列' : '显示全部列' }}
        </el-button>
      </el-col>
      <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 数据导入对话框 -->
    <el-dialog title="数据导入" v-model="excelDialogVisible" width="400px" append-to-body>
      <el-upload
          ref="uploadRef"
          class="upload-demo"
          :action="uploadExcelUrl"
          :headers="headers"
          :on-success="handleUploadSuccess"
          :on-error="handleUploadError"
          :before-upload="handleBeforeUpload"
          :limit="1"
          :auto-upload="false"
      >
        <template #trigger>
          <el-button type="primary">上传文件</el-button>
        </template>
        <el-button class="ml-3" type="success" @click="submitUpload">上传</el-button>
        <template #tip>
          <div class="el-upload__tip">上传文件仅支持xls/xlsx格式，大小不超过2048M</div>
        </template>
      </el-upload>
    </el-dialog>

    <!-- 表格：按实体类顺序排列列 -->
    <el-table
        v-loading="loading"
        :data="importList"
        @selection-change="handleSelectionChange"
        border
        stripe
        class="table-hover-effect"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="类型" align="center" prop="stuType" min-width="80" />
      <el-table-column label="考生编号" align="center" prop="ksbh" min-width="120" />
      <el-table-column label="姓名" align="center" prop="xm" min-width="100" />
      <el-table-column label="学号" align="center" prop="xh" min-width="100" />
      <el-table-column label="证件类型" align="center" prop="zjlx" min-width="100" :formatter="formatCertificateType" />
      <el-table-column label="身份证号" align="center" prop="zjhm" min-width="180" />
      <el-table-column label="出生日期" align="center" prop="csrq" min-width="120" />
      <el-table-column label="民族" align="center" prop="mzm" min-width="100"
                       :formatter="formatNation" />
      <el-table-column label="录取专业名称" align="center" prop="lqzymc" min-width="150" />
      <el-table-column label="毕业单位" align="center" prop="bydw" min-width="150" />
      <el-table-column label="毕业年月" align="center" prop="byny" min-width="120" />
      <el-table-column label="学生资格状态" align="center" prop="xszgzc" min-width="120">
        <template #default="scope">
          <span>{{ sys_student_qualification_status.find(item => item.value === scope.row.xszgzc)?.label || scope.row.xszgzc }}</span>
        </template>
      </el-table-column>
      <el-table-column label="导入状态" align="center" prop="drzt" min-width="120">
        <template #default="scope">
          <span :class="getStatusClass(scope.row.drzt)">
            {{ rxdrzt.find(item => item.value === scope.row.drzt)?.label || scope.row.drzt }}
          </span>
        </template>
      </el-table-column>

      <!-- 次要列：按实体类顺序排列，默认隐藏，通过按钮切换显示 -->
      <template v-if="showAllColumns">
<!--        <el-table-column label="性别码" align="center" prop="xbm" min-width="80" />-->
        <el-table-column label="学生性别" align="center" prop="xbm" min-width="80" >
          <template #default="scope">
            {{ sys_user_sex.find(item => item.value === scope.row.xbm)?.label || '无' }}
          </template>
        </el-table-column>
        <el-table-column label="婚姻状况" align="center" prop="hfm" min-width="100" >
          <template #default="scope">
            {{ marital_status.find(item => item.value === scope.row.hfm)?.label || '无' }}
          </template>
        </el-table-column>
        <el-table-column label="现役军人码" align="center" prop="xyjrm" min-width="100" />
        <el-table-column label="政治面貌" align="center" prop="zzmmm" min-width="100" :formatter="formatPoliticalStatus" />
        <el-table-column label="户口所在地码" align="center" prop="hkszdm" min-width="120"
                         :formatter="formatHukouLocation" />
        <el-table-column label="户口所在地详细地址" align="center" prop="hkszdxxdz" min-width="150" />
        <el-table-column label="考生档案所在单位" align="center" prop="daszdw" min-width="150" />
        <el-table-column label="考生档案所在单位地址" align="center" prop="daszdwdz" min-width="150" />
        <el-table-column label="考生档案所在单位邮政编码" align="center" prop="daszdwyzbm" min-width="120" />
        <el-table-column label="考生来源" align="center" prop="kslym" min-width="100">
          <template #default="scope">
            <span>{{ sys_examinee_source_code.find(item => item.value === scope.row.kslym)?.label || scope.row.kslym }}</span>
          </template>
        </el-table-column>
        <el-table-column label="毕业单位码" align="center" prop="bydwm" min-width="100" />
        <el-table-column label="毕业专业代码" align="center" prop="byzydm" min-width="100" />
        <el-table-column label="毕业专业名称" align="center" prop="byzymc" min-width="150" />
        <el-table-column label="学习形式" align="center" prop="xxxs" min-width="100">
          <template #default="scope">
            <span>{{ sys_learning_mode.find(item => item.value === scope.row.xxxs)?.label || scope.row.xxxs }}</span>
          </template>
        </el-table-column>
        <el-table-column label="最后学历码" align="center" prop="xlm" min-width="100" />
        <el-table-column label="学历证书编号" align="center" prop="xlzsbh" min-width="150" />
        <el-table-column label="注册学号" align="center" prop="zcxh" min-width="100" />
        <el-table-column label="最后学位码" align="center" prop="xwm" min-width="100" />
        <el-table-column label="学位证书编号" align="center" prop="xwzsbh" min-width="150" />
        <el-table-column label="录取单位代码" align="center" prop="lqdwdm" min-width="100" />
        <el-table-column label="录取单位名称" align="center" prop="lqdwmc" min-width="150" />
        <el-table-column label="录取专业代码" align="center" prop="lqzydm" min-width="100" />
        <el-table-column label="专业代码及名称" align="center" prop="zydmjmc" min-width="150" />
        <el-table-column label="考试方式" align="center" prop="ksfsm" min-width="100">
          <template #default="scope">
            <span>{{ test_format.find(item => item.value === scope.row.ksfsm)?.label || scope.row.ksfsm }}</span>
          </template>
        </el-table-column>
        <el-table-column label="专项计划" align="center" prop="zxjh" min-width="100" />
        <el-table-column label="录取类别" align="center" prop="lqlbm" min-width="100">
          <template #default="scope">
            <span>{{ sys_admission_category_code.find(item => item.value === scope.row.lqlbm)?.label || scope.row.lqlbm }}</span>
          </template>
        </el-table-column>
        <el-table-column label="定向就业单位所在地码" align="center" prop="dxwpdwszdm" min-width="120" />
        <el-table-column label="定向就业单位" align="center" prop="dxwpdw" min-width="150" />
        <el-table-column label="录取学院码" align="center" prop="lqyxsm" min-width="100" />
        <el-table-column label="学院名称" align="center" prop="xymc" min-width="150" />
        <el-table-column label="学院代码及名称" align="center" prop="xydmjmc" min-width="150" />
        <el-table-column label="政治理论码" align="center" prop="zzllm" min-width="100" />
        <el-table-column label="政治理论名称" align="center" prop="zzllmc" min-width="150" />
        <el-table-column label="外国语码" align="center" prop="wgym" min-width="100" />
        <el-table-column label="外国语名称" align="center" prop="wgymc" min-width="150" />
        <el-table-column label="业务课1码" align="center" prop="ywk1m" min-width="100" />
        <el-table-column label="业务课1名称" align="center" prop="ywk1mc" min-width="150" />
        <el-table-column label="业务课2码" align="center" prop="ywk2m" min-width="100" />
        <el-table-column label="业务课2名称" align="center" prop="ywk2mc" min-width="150" />
        <el-table-column label="政治理论成绩" align="center" prop="zzll" min-width="100" />
        <el-table-column label="外国语成绩" align="center" prop="wgy" min-width="100" />
        <el-table-column label="业务课1成绩" align="center" prop="ywk1" min-width="100" />
        <el-table-column label="业务课2成绩" align="center" prop="ywk2" min-width="100" />
        <el-table-column label="总分" align="center" prop="zf" min-width="80" />
        <el-table-column label="复试成绩" align="center" prop="fscj" min-width="100" />
        <el-table-column label="总成绩折算办法" align="center" prop="zcjzsbf" min-width="120" />
        <el-table-column label="总成绩" align="center" prop="zcj" min-width="100" />
        <el-table-column label="加试1名称" align="center" prop="js1mc" min-width="100" />
        <el-table-column label="加试1成绩" align="center" prop="js1cj" min-width="100" />
        <el-table-column label="加试2名称" align="center" prop="js2mc" min-width="100" />
        <el-table-column label="加试2成绩" align="center" prop="js2cj" min-width="100" />
        <el-table-column label="保留资格年限" align="center" prop="blzgnx" min-width="100" />
        <el-table-column label="评估" align="center" prop="pg" min-width="80">
          <template #default="scope">
            <span>{{ sys_student_assessment.find(item => item.value === scope.row.pg)?.label || scope.row.pg }}</span>
          </template>
        </el-table-column>
        <el-table-column label="所在省市码" align="center" prop="szssm" min-width="100" />
        <el-table-column label="备注" align="center" prop="bz" min-width="150" />
        <el-table-column label="录取培养单位码" align="center" prop="lhpydwm" min-width="120" />
        <el-table-column label="录取培养单位" align="center" prop="lhpydw" min-width="150" />
        <el-table-column label="学制排序" align="center" prop="xzpx" min-width="100" />
        <el-table-column label="学制" align="center" prop="xz" min-width="80" />
        <el-table-column label="录取学习方式" align="center" prop="lqxxfs" min-width="120">
          <template #default="scope">
            <span>{{ sys_admission_learning_mode.find(item => item.value === scope.row.lqxxfs)?.label || scope.row.lqxxfs }}</span>
          </template>
        </el-table-column>
        <el-table-column label="入伍前所在高校入学年月" align="center" prop="rwqrxny" min-width="120" />
        <el-table-column label="入伍前所在高校所在省市码" align="center" prop="rwqgxssm" min-width="120" />
        <el-table-column label="入伍前所在高校代码" align="center" prop="rwqgxdm" min-width="120" />
        <el-table-column label="入伍前所在高校名称" align="center" prop="rwqgxmc" min-width="150" />
        <el-table-column label="入伍前所在高校学习形式" align="center" prop="rwqxxxs" min-width="120">
          <template #default="scope">
            <span>{{ sys_learning_mode.find(item => item.value === scope.row.rwqxxxs)?.label || scope.row.rwqxxxs }}</span>
          </template>
        </el-table-column>
        <el-table-column label="入伍前所在高校学习专业代码" align="center" prop="rwqzydm" min-width="120" />
        <el-table-column label="入伍前所在高校学习专业名称" align="center" prop="rwqzymc" min-width="150" />
        <el-table-column label="入伍前所在高校毕业证书编号" align="center" prop="rwqxlzsbh" min-width="150" />
        <el-table-column label="批准入伍年月" align="center" prop="rwny" min-width="120" />
        <el-table-column label="批准入伍机关名称" align="center" prop="rwpzdw" min-width="150" />
        <el-table-column label="批准退役年月" align="center" prop="tyny" min-width="120" />
        <el-table-column label="批准退役机关名称" align="center" prop="typzdw" min-width="150" />
        <el-table-column label="入伍批准书编号" align="center" prop="rwpzsbh" min-width="150" />
        <el-table-column label="退出现役证编号" align="center" prop="tcxyzbh" min-width="150" />
        <el-table-column label="录取研究方向代码" align="center" prop="lqyjfxdm" min-width="120" />
        <el-table-column label="录取研究方向名称" align="center" prop="lqyjfxmc" min-width="150" />
        <el-table-column label="公共管理类别" align="center" prop="ggjhlb" min-width="100">
          <template #default="scope">
            <span>{{ sys_public_administration_category.find(item => item.value === scope.row.ggjhlb)?.label || scope.row.ggjhlb }}</span>
          </template>
        </el-table-column>
        <el-table-column label="通信地址" align="center" prop="txdz" min-width="150" />
        <el-table-column label="联系方式" align="center" prop="lxfs" min-width="120" />
        <el-table-column label="校验状态" align="center" prop="jyzt" min-width="100" />
      </template>

      <el-table-column label="操作" align="center" min-width="140">
        <template #default="scope">
          <el-button
              link
              type="primary"
              icon="Edit"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['student:import:edit']"
              class="btn-operation"
          >修改</el-button>
          <el-button
              link
              type="danger"
              icon="Delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['student:import:remove']"
              class="btn-operation"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        @pagination="getList"
        layout="total, sizes, prev, pager, next, jumper"
    />
    <!-- 在模板中添加导入结果对话框 -->
    <el-dialog
        title="导入结果详情"
        v-model="resultDialogVisible"
        width="500px"
        append-to-body>
      <div class="result-container">
        <div class="result-item">
          <span class="result-label">导入成功：</span>
          <span class="result-value success">{{ importResult.insertCount }} 条</span>
        </div>
        <div class="result-item">
          <span class="result-label">重复跳过：</span>
          <span class="result-value warning">{{ importResult.duplicateCount }} 条</span>
        </div>
        <!-- 优化后的导入结果对话框中的重复学号展示部分 -->
        <div v-if="importResult.duplicateXh && importResult.duplicateXh.length" class="duplicate-section">
          <div class="duplicate-header">
            <p class="duplicate-title">重复学号列表：</p>
            <el-button
                type="text"
                size="small"
                @click="copyDuplicateXh"
                class="copy-btn"
            >
              <i class="el-icon-document-copy"></i> 复制全部
            </el-button>
          </div>
          <div class="duplicate-tags-container">
            <el-tag
                v-for="xh in importResult.duplicateXh"
                :key="xh"
                type="warning"
                effect="dark"
                class="duplicate-tag"
            >
              {{ xh }}
            </el-tag>
          </div>
        </div>
      </div>
      <template #footer>
        <el-button type="primary" @click="resultDialogVisible = false">确定</el-button>
      </template>
    </el-dialog>
    <!-- 添加/修改对话框：按实体类顺序排列表单字段 -->
    <el-dialog
        :title="title"
        v-model="open"
        width="900px"
        append-to-body
        :close-on-click-modal="false"
    >
      <div class="dialog-container">
        <!-- 表单滚动容器 -->
        <div class="form-scroll-container">
          <el-form
              ref="importRef"
              :model="form"
              :rules="rules"
              label-width="120px"
              class="dialog-form"
          >
            <!-- 基本信息卡片 -->
            <el-card class="form-card">
              <template #header>
                <div class="card-header">
                  <i class="el-icon-user"></i>
                  <span class="card-title">基本信息</span>
                </div>
              </template>
              <div class="form-grid">
                <el-form-item label="类型" prop="stuType">
                  <el-select
                      v-model="queryParams.stuType"
                      placeholder="请选择类型"
                      clearable
                      @change="handleQuery"
                      style="width: 180px"
                  >
                    <el-option
                        v-for="dict in sys_student_admission_type"
                        :key="dict.value"
                        :label="dict.label"
                        :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="考生编号" prop="ksbh" class="form-item">
                  <el-input v-model="form.ksbh" placeholder="请输入考生编号" class="form-control" />
                </el-form-item>
                <el-form-item label="姓名" prop="xm" class="form-item">
                  <el-input v-model="form.xm" placeholder="请输入姓名" class="form-control" />
                </el-form-item>
                <el-form-item label="学号" prop="xh" class="form-item">
                  <el-input v-model="form.xh" placeholder="请输入学号" class="form-control" />
                </el-form-item>
                <el-form-item label="证件类型" prop="zjlx" class="form-item">
                  <el-select v-model="queryParams.zjlx" placeholder="请选择证件类型" filterable class="form-control">
                    <el-option
                        v-for="item in certificateTypeList"
                        :key="item.cardtValue"
                        :label="item.cardtLabel"
                        :value="item.cardtValue"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="身份证号" prop="zjhm" class="form-item">
                  <el-input v-model="form.zjhm" placeholder="请输入身份证号" class="form-control" />
                </el-form-item>
                <el-form-item label="出生日期" prop="csrq" class="form-item">
                  <el-date-picker
                      clearable
                      v-model="form.csrq"
                      type="date"
                      value-format="yyyyMMdd"
                      placeholder="选择出生日期"
                      class="form-control"
                  />
                </el-form-item>
                <el-form-item label="民族" prop="mzm" class="form-item">
                  <el-select v-model="form.mzm" placeholder="请选择民族" filterable class="form-control">
                    <el-option
                        v-for="item in nationList"
                        :key="item.id"
                        :label="item.nadictLabel"
                        :value="item.nadictValue"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="性别" prop="xbm" class="form-item">
                  <el-select
                      v-model="queryParams.xbm"
                      placeholder="请选择性别"
                      filterable

                  >
                    <el-option
                        v-for="dict in sys_user_sex"
                        :key="dict.id"
                        :label="dict.label"
                        :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="婚姻状况" prop="hfm" class="form-item">
                     <el-select v-model="form.hfm" placeholder="请选择婚姻状况" clearable class="form-control">
                       <el-option
                             v-for="dict in marital_status"
                             :key="dict.value"
                             :label="dict.label"
                            :value="dict.value"
                         />
                    </el-select>
                </el-form-item>
                <el-form-item label="现役军人码" prop="xyjrm" class="form-item">
                  <el-input v-model="form.xyjrm" placeholder="请输入现役军人码" class="form-control" />
                </el-form-item>
                <el-form-item label="政治面貌" prop="zzmmm" class="form-item">
                  <el-select v-model="queryParams.zzmmm" placeholder="请选择政治面貌" filterable class="form-control">
                    <el-option
                        v-for="item in politicalStatusList"
                        :key="item.politicalValue"
                        :label="item.politicalLabel"
                        :value="item.politicalValue"
                    />
                  </el-select>
                </el-form-item>
              </div>
            </el-card>

            <!-- 户口信息卡片 -->
            <el-card class="form-card">
              <template #header>
                <div class="card-header">
                  <i class="el-icon-home"></i>
                  <span class="card-title">户口信息</span>
                </div>
              </template>
              <div class="form-grid">
                <el-form-item label="户口所在地码" prop="hkszdm" class="form-item">
                  <el-cascader
                      v-model="selectHuKouSuoZaiDi"
                      :options="options"
                      @change="handleChangeHuKouSuoZaiDi"
                      placeholder="选择户口所在地"
                      class="form-control"
                  />
                </el-form-item>
                <el-form-item label="户口所在地详细地址" prop="hkszdxxdz" class="form-item full-width">
                  <el-input v-model="form.hkszdxxdz" placeholder="请输入户口所在地详细地址" class="form-control" />
                </el-form-item>
              </div>
            </el-card>

            <!-- 档案信息卡片 -->
            <el-card class="form-card">
              <template #header>
                <div class="card-header">
                  <i class="el-icon-folder"></i>
                  <span class="card-title">档案信息</span>
                </div>
              </template>
              <div class="form-grid">
                <el-form-item label="考生档案所在单位" prop="daszdw" class="form-item">
                  <el-input v-model="form.daszdw" placeholder="请输入考生档案所在单位" class="form-control" />
                </el-form-item>
                <el-form-item label="考生档案所在单位地址" prop="daszdwdz" class="form-item full-width">
                  <el-input v-model="form.daszdwdz" placeholder="请输入考生档案所在单位地址" class="form-control" />
                </el-form-item>
                <el-form-item label="考生档案所在单位邮政编码" prop="daszdwyzbm" class="form-item">
                  <el-input v-model="form.daszdwyzbm" placeholder="请输入邮政编码" class="form-control" />
                </el-form-item>
                <el-form-item label="考生来源" prop="kslym" class="form-item">
                     <el-select v-model="form.kslym" placeholder="请选择考生来源" clearable class="form-control">
                       <el-option
                             v-for="dict in sys_examinee_source_code"
                             :key="dict.value"
                             :label="dict.label"
                             :value="dict.value"
                         />
                     </el-select>
                </el-form-item>

              </div>
            </el-card>

            <!-- 毕业信息卡片 -->
            <el-card class="form-card">
              <template #header>
                <div class="card-header">
                  <i class="el-icon-graduation-cap"></i>
                  <span class="card-title">毕业信息</span>
                </div>
              </template>
              <div class="form-grid">
                <el-form-item label="毕业单位码" prop="bydwm" class="form-item">
                  <el-input v-model="form.bydwm" placeholder="请输入毕业单位码" class="form-control" />
                </el-form-item>
                <el-form-item label="毕业单位" prop="bydw" class="form-item">
                  <el-input v-model="form.bydw" placeholder="请输入毕业单位" class="form-control" />
                </el-form-item>
                <el-form-item label="毕业专业代码" prop="byzydm" class="form-item">
                  <el-input v-model="form.byzydm" placeholder="请输入毕业专业代码" class="form-control" />
                </el-form-item>
                <el-form-item label="毕业专业名称" prop="byzymc" class="form-item">
                  <el-input v-model="form.byzymc" placeholder="请输入毕业专业名称" class="form-control" />
                </el-form-item>
                <el-form-item label="学习形式" prop="xxxs" class="form-item">
                     <el-select v-model="form.xxxs" placeholder="请选择学习形式" clearable class="form-control">
                       <el-option
                             v-for="dict in sys_learning_mode"
                             :key="dict.value"
                            :label="dict.label"
                            :value="dict.value"
                  />
                    </el-select>
                </el-form-item>

                <el-form-item label="最后学历码" prop="xlm" class="form-item">
                  <el-input v-model="form.xlm" placeholder="请输入最后学历码" class="form-control" />
                </el-form-item>
                <el-form-item label="学历证书编号" prop="xlzsbh" class="form-item">
                  <el-input v-model="form.xlzsbh" placeholder="请输入学历证书编号" class="form-control" />
                </el-form-item>
                <el-form-item label="毕业年月" prop="byny" class="form-item">
                  <el-date-picker
                      clearable
                      v-model="form.byny"
                      type="month"
                      value-format="yyyyMM"
                      placeholder="选择毕业年月"
                      class="form-control"
                  />
                </el-form-item>
                <el-form-item label="注册学号" prop="zcxh" class="form-item">
                  <el-input v-model="form.zcxh" placeholder="请输入注册学号" class="form-control" />
                </el-form-item>
                <el-form-item label="最后学位码" prop="xwm" class="form-item">
                  <el-input v-model="form.xwm" placeholder="请输入最后学位码" class="form-control" />
                </el-form-item>
                <el-form-item label="学位证书编号" prop="xwzsbh" class="form-item">
                  <el-input v-model="form.xwzsbh" placeholder="请输入学位证书编号" class="form-control" />
                </el-form-item>
              </div>
            </el-card>

            <!-- 录取信息卡片 -->
            <el-card class="form-card">
              <template #header>
                <div class="card-header">
                  <i class="el-icon-trophy"></i>
                  <span class="card-title">录取信息</span>
                </div>
              </template>
              <div class="form-grid">
                <el-form-item label="录取单位代码" prop="lqdwdm" class="form-item">
                  <el-input v-model="form.lqdwdm" placeholder="请输入录取单位代码" class="form-control" />
                </el-form-item>
                <el-form-item label="录取单位名称" prop="lqdwmc" class="form-item">
                  <el-input v-model="form.lqdwmc" placeholder="请输入录取单位名称" class="form-control" />
                </el-form-item>
                <el-form-item label="录取专业代码" prop="lqzydm" class="form-item">
                  <el-input v-model="form.lqzydm" placeholder="请输入录取专业代码" class="form-control" />
                </el-form-item>
                <el-form-item label="录取专业名称" prop="lqzymc" class="form-item">
                  <el-input v-model="form.lqzymc" placeholder="请输入录取专业名称" class="form-control" />
                </el-form-item>
                <el-form-item label="专业代码及名称" prop="zydmjmc" class="form-item full-width">
                  <el-input v-model="form.zydmjmc" placeholder="请输入专业代码及名称" class="form-control" />
                </el-form-item>
                <el-form-item label="考试方式" prop="ksfsm" class="form-item">
                     <el-select v-model="form.ksfsm" placeholder="请选择考试方式" clearable class="form-control">
                       <el-option
                             v-for="dict in test_format"
                             :key="dict.value"
                             :label="dict.label"
                             :value="dict.value"
                         />
                     </el-select>
                </el-form-item>
                <el-form-item label="专项计划" prop="zxjh" class="form-item">
                  <el-input v-model="form.zxjh" placeholder="请输入专项计划" class="form-control" />
                </el-form-item>
                <el-form-item label="录取类别" prop="lqlbm" class="form-item">
                     <el-select v-model="form.lqlbm" placeholder="请选择录取类别" clearable class="form-control">
                      <el-option
                             v-for="dict in sys_admission_category_code"
                             :key="dict.value"
                             :label="dict.label"
                            :value="dict.value"
                        />
                     </el-select>
                </el-form-item>
              </div>
            </el-card>

            <!-- 定向就业信息卡片 -->
            <el-card class="form-card">
              <template #header>
                <div class="card-header">
                  <i class="el-icon-briefcase"></i>
                  <span class="card-title">定向就业信息</span>
                </div>
              </template>
              <div class="form-grid">
                <el-form-item label="定向就业单位所在地码" prop="dxwpdwszdm" class="form-item">
                  <el-input v-model="form.dxwpdwszdm" placeholder="请输入定向就业单位所在地码" class="form-control" />
                </el-form-item>
                <el-form-item label="定向就业单位" prop="dxwpdw" class="form-item full-width">
                  <el-input v-model="form.dxwpdw" placeholder="请输入定向就业单位" class="form-control" />
                </el-form-item>
              </div>
            </el-card>

            <!-- 学院信息卡片 -->
            <el-card class="form-card">
              <template #header>
                <div class="card-header">
                  <i class="el-icon-building"></i>
                  <span class="card-title">学院信息</span>
                </div>
              </template>
              <div class="form-grid">
                <el-form-item label="录取学院码" prop="lqyxsm" class="form-item">
                  <el-input v-model="form.lqyxsm" placeholder="请输入录取学院码" class="form-control" />
                </el-form-item>
                <el-form-item label="学院名称" prop="xymc" class="form-item">
                  <el-input v-model="form.xymc" placeholder="请输入学院名称" class="form-control" />
                </el-form-item>
                <el-form-item label="学院代码及名称" prop="xydmjmc" class="form-item full-width">
                  <el-input v-model="form.xydmjmc" placeholder="请输入学院代码及名称" class="form-control" />
                </el-form-item>
              </div>
            </el-card>

            <!-- 考试成绩信息卡片 -->
            <el-card class="form-card">
              <template #header>
                <div class="card-header">
                  <i class="el-icon-edit-outline"></i>
                  <span class="card-title">考试成绩信息</span>
                </div>
              </template>
              <div class="form-grid">
                <el-form-item label="政治理论码" prop="zzllm" class="form-item">
                  <el-input v-model="form.zzllm" placeholder="请输入政治理论码" class="form-control" />
                </el-form-item>
                <el-form-item label="政治理论名称" prop="zzllmc" class="form-item">
                  <el-input v-model="form.zzllmc" placeholder="请输入政治理论名称" class="form-control" />
                </el-form-item>
                <el-form-item label="外国语码" prop="wgym" class="form-item">
                  <el-input v-model="form.wgym" placeholder="请输入外国语码" class="form-control" />
                </el-form-item>
                <el-form-item label="外国语名称" prop="wgymc" class="form-item">
                  <el-input v-model="form.wgymc" placeholder="请输入外国语名称" class="form-control" />
                </el-form-item>
                <el-form-item label="业务课1码" prop="ywk1m" class="form-item">
                  <el-input v-model="form.ywk1m" placeholder="请输入业务课1码" class="form-control" />
                </el-form-item>
                <el-form-item label="业务课1名称" prop="ywk1mc" class="form-item">
                  <el-input v-model="form.ywk1mc" placeholder="请输入业务课1名称" class="form-control" />
                </el-form-item>
                <el-form-item label="业务课2码" prop="ywk2m" class="form-item">
                  <el-input v-model="form.ywk2m" placeholder="请输入业务课2码" class="form-control" />
                </el-form-item>
                <el-form-item label="业务课2名称" prop="ywk2mc" class="form-item">
                  <el-input v-model="form.ywk2mc" placeholder="请输入业务课2名称" class="form-control" />
                </el-form-item>
                <el-form-item label="政治理论成绩" prop="zzll" class="form-item">
                  <el-input v-model="form.zzll" placeholder="请输入政治理论成绩" type="number" class="form-control" />
                </el-form-item>
                <el-form-item label="外国语成绩" prop="wgy" class="form-item">
                  <el-input v-model="form.wgy" placeholder="请输入外国语成绩" type="number" class="form-control" />
                </el-form-item>
                <el-form-item label="业务课1成绩" prop="ywk1" class="form-item">
                  <el-input v-model="form.ywk1" placeholder="请输入业务课1成绩" type="number" class="form-control" />
                </el-form-item>
                <el-form-item label="业务课2成绩" prop="ywk2" class="form-item">
                  <el-input v-model="form.ywk2" placeholder="请输入业务课2成绩" type="number" class="form-control" />
                </el-form-item>
                <el-form-item label="总分" prop="zf" class="form-item">
                  <el-input v-model="form.zf" placeholder="请输入总分" type="number" class="form-control" />
                </el-form-item>
                <el-form-item label="复试成绩" prop="fscj" class="form-item">
                  <el-input v-model="form.fscj" placeholder="请输入复试成绩" type="number" class="form-control" />
                </el-form-item>
                <el-form-item label="总成绩折算办法" prop="zcjzsbf" class="form-item">
                  <el-input v-model="form.zcjzsbf" placeholder="请输入总成绩折算办法" class="form-control" />
                </el-form-item>
                <el-form-item label="总成绩" prop="zcj" class="form-item">
                  <el-input v-model="form.zcj" placeholder="请输入总成绩" type="number" class="form-control" />
                </el-form-item>
                <el-form-item label="加试1名称" prop="js1mc" class="form-item">
                  <el-input v-model="form.js1mc" placeholder="请输入加试1名称" class="form-control" />
                </el-form-item>
                <el-form-item label="加试1成绩" prop="js1cj" class="form-item">
                  <el-input v-model="form.js1cj" placeholder="请输入加试1成绩" type="number" class="form-control" />
                </el-form-item>
                <el-form-item label="加试2名称" prop="js2mc" class="form-item">
                  <el-input v-model="form.js2mc" placeholder="请输入加试2名称" class="form-control" />
                </el-form-item>
                <el-form-item label="加试2成绩" prop="js2cj" class="form-item">
                  <el-input v-model="form.js2cj" placeholder="请输入加试2成绩" type="number" class="form-control" />
                </el-form-item>
              </div>
            </el-card>

            <!-- 其他信息卡片 -->
            <el-card class="form-card">
              <template #header>
                <div class="card-header">
                  <i class="el-icon-info"></i>
                  <span class="card-title">其他信息</span>
                </div>
              </template>
              <div class="form-grid">
                <el-form-item label="保留资格年限" prop="blzgnx" class="form-item">
                  <el-input v-model="form.blzgnx" placeholder="请输入保留资格年限" class="form-control" />
                </el-form-item>
                <el-form-item label="评估" prop="pg" class="form-item">
                     <el-select v-model="form.pg" placeholder="请选择评估" clearable class="form-control">
                       <el-option
                             v-for="dict in sys_student_assessment"
                             :key="dict.value"
                             :label="dict.label"
                             :value="dict.value"
                         />
                     </el-select>
                </el-form-item>
                <el-form-item label="学生资格状态" prop="xszgzc" class="form-item">
                     <el-select v-model="form.xszgzc" placeholder="请选择学生资格状态" clearable class="form-control">
                       <el-option
                             v-for="dict in sys_student_qualification_status"
                             :key="dict.value"
                             :label="dict.label"
                             :value="dict.value"
                         />
                     </el-select>
                </el-form-item>

                <el-form-item label="所在省市码" prop="szssm" class="form-item">
                  <el-input v-model="form.szssm" placeholder="请输入所在省市码" class="form-control" />
                </el-form-item>
                <el-form-item label="备注" prop="bz" class="form-item full-width">
                  <el-input v-model="form.bz" type="textarea" placeholder="请输入备注" rows="3" class="form-control" />
                </el-form-item>
                <el-form-item label="录取培养单位码" prop="lhpydwm" class="form-item">
                  <el-input v-model="form.lhpydwm" placeholder="请输入录取培养单位码" class="form-control" />
                </el-form-item>
                <el-form-item label="录取培养单位" prop="lhpydw" class="form-item">
                  <el-input v-model="form.lhpydw" placeholder="请输入录取培养单位" class="form-control" />
                </el-form-item>
                <el-form-item label="学制排序" prop="xzpx" class="form-item">
                  <el-input v-model="form.xzpx" placeholder="请输入学制排序" class="form-control" />
                </el-form-item>
                <el-form-item label="学制" prop="xz" class="form-item">
                  <el-input v-model="form.xz" placeholder="请输入学制" class="form-control" />
                </el-form-item>
                <el-form-item label="录取学习方式" prop="lqxxfs" class="form-item">
                     <el-select v-model="form.lqxxfs" placeholder="请选择录取学习方式" clearable class="form-control">
                       <el-option
                             v-for="dict in sys_admission_learning_mode"
                             :key="dict.value"
                             :label="dict.label"
                             :value="dict.value"
                        />
                    </el-select>
                </el-form-item>
              </div>
            </el-card>

            <!-- 入伍退役信息卡片 -->
            <el-card class="form-card">
              <template #header>
                <div class="card-header">
                  <i class="el-icon-flag"></i>
                  <span class="card-title">入伍退役信息</span>
                </div>
              </template>
              <div class="form-grid">
                <el-form-item label="入伍前所在高校入学年月" prop="rwqrxny" class="form-item">
                  <el-date-picker
                      clearable
                      v-model="form.rwqrxny"
                      type="month"
                      value-format="yyyyMM"
                      placeholder="选择入学年月"
                      class="form-control"
                  />
                </el-form-item>
                <el-form-item label="入伍前所在高校所在省市码" prop="rwqgxssm" class="form-item">
                  <el-input v-model="form.rwqgxssm" placeholder="请输入省市码" class="form-control" />
                </el-form-item>
                <el-form-item label="入伍前所在高校代码" prop="rwqgxdm" class="form-item">
                  <el-input v-model="form.rwqgxdm" placeholder="请输入高校代码" class="form-control" />
                </el-form-item>
                <el-form-item label="入伍前所在高校名称" prop="rwqgxmc" class="form-item">
                  <el-input v-model="form.rwqgxmc" placeholder="请输入高校名称" class="form-control" />
                </el-form-item>
                <el-form-item label="入伍前所在高校学习形式" prop="rwqxxxs" class="form-item">
                     <el-select v-model="form.rwqxxxs" placeholder="请选择学习形式" clearable class="form-control">
                       <el-option
                             v-for="dict in sys_learning_mode"
                             :key="dict.value"
                             :label="dict.label"
                             :value="dict.value"
                         />
                     </el-select>
                </el-form-item>
                <el-form-item label="入伍前所在高校学习专业代码" prop="rwqzydm" class="form-item">
                  <el-input v-model="form.rwqzydm" placeholder="请输入专业代码" class="form-control" />
                </el-form-item>
                <el-form-item label="入伍前所在高校学习专业名称" prop="rwqzymc" class="form-item">
                  <el-input v-model="form.rwqzymc" placeholder="请输入专业名称" class="form-control" />
                </el-form-item>
                <el-form-item label="入伍前所在高校毕业证书编号" prop="rwqxlzsbh" class="form-item">
                  <el-input v-model="form.rwqxlzsbh" placeholder="请输入毕业证书编号" class="form-control" />
                </el-form-item>
                <el-form-item label="批准入伍年月" prop="rwny" class="form-item">
                  <el-date-picker
                      clearable
                      v-model="form.rwny"
                      type="month"
                      value-format="yyyyMM"
                      placeholder="选择入伍年月"
                      class="form-control"
                  />
                </el-form-item>
                <el-form-item label="批准入伍机关名称" prop="rwpzdw" class="form-item">
                  <el-input v-model="form.rwpzdw" placeholder="请输入机关名称" class="form-control" />
                </el-form-item>
                <el-form-item label="批准退役年月" prop="tyny" class="form-item">
                  <el-date-picker
                      clearable
                      v-model="form.tyny"
                      type="month"
                      value-format="yyyyMM"
                      placeholder="选择退役年月"
                      class="form-control"
                  />
                </el-form-item>
                <el-form-item label="批准退役机关名称" prop="typzdw" class="form-item">
                  <el-input v-model="form.typzdw" placeholder="请输入机关名称" class="form-control" />
                </el-form-item>
                <el-form-item label="入伍批准书编号" prop="rwpzsbh" class="form-item">
                  <el-input v-model="form.rwpzsbh" placeholder="请输入批准书编号" class="form-control" />
                </el-form-item>
                <el-form-item label="退出现役证编号" prop="tcxyzbh" class="form-item">
                  <el-input v-model="form.tcxyzbh" placeholder="请输入退役证编号" class="form-control" />
                </el-form-item>
              </div>
            </el-card>

            <!-- 研究方向及其他信息卡片 -->
            <el-card class="form-card">
              <template #header>
                <div class="card-header">
                  <i class="el-icon-lightbulb"></i>
                  <span class="card-title">研究方向及其他信息</span>
                </div>
              </template>
              <div class="form-grid">
                <el-form-item label="录取研究方向代码" prop="lqyjfxdm" class="form-item">
                  <el-input v-model="form.lqyjfxdm" placeholder="请输入研究方向代码" class="form-control" />
                </el-form-item>
                <el-form-item label="录取研究方向名称" prop="lqyjfxmc" class="form-item">
                  <el-input v-model="form.lqyjfxmc" placeholder="请输入研究方向名称" class="form-control" />
                </el-form-item>
                <el-form-item label="公共管理类别" prop="ggjhlb" class="form-item">
                     <el-select v-model="form.ggjhlb" placeholder="请选择公共管理类别" clearable class="form-control">
                       <el-option
                             v-for="dict in sys_public_administration_category"
                             :key="dict.value"
                             :label="dict.label"
                             :value="dict.value"
                         />
                     </el-select>
                </el-form-item>

                <el-form-item label="通信地址" prop="txdz" class="form-item full-width">
                  <el-input v-model="form.txdz" placeholder="请输入通信地址" class="form-control" />
                </el-form-item>
                <el-form-item label="联系方式" prop="lxfs" class="form-item">
                  <el-input v-model="form.lxfs" placeholder="请输入联系方式" class="form-control" />
                </el-form-item>
                <el-form-item label="导入状态" prop="drzt" class="form-item">
                  <el-select v-model="form.drzt" placeholder="请选择导入状态" filterable class="form-control">
                    <el-option
                        v-for="dict in rxdrzt"
                        :key="dict.id"
                        :label="dict.label"
                        :value="dict.value"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="校验状态" prop="jyzt" class="form-item">
                  <el-input v-model="form.jyzt" placeholder="请输入校验状态" class="form-control" />
                </el-form-item>
              </div>
            </el-card>
          </el-form>
        </div>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cancel" class="btn-secondary">取 消</el-button>
          <el-button type="primary" @click="submitForm" class="btn-primary">确 定</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="StudentInfoImport">
import { listImport, getImport, delImport, addImport, updateImport } from "@/api/student/import";
import { getToken } from "@/utils/auth";
import { loadAllParams } from "@/api/page.js";
import {listGertificatetype} from "@/api/dictionaries/gertificatetype.js";
import { listPoliticalstatus } from "@/api/dictionaries/politicalstatus.js"
import { listNation } from "@/api/dictionaries/nation";
import { regionData , codeToText } from 'element-china-area-data';
import { ref, reactive, toRefs, getCurrentInstance, onMounted, computed } from 'vue';

const { proxy } = getCurrentInstance();
const { sys_student_admission_type,sys_examinee_source_code,rxdrzt,sys_user_sex,test_format,marital_status,sys_student_qualification_status,sys_learning_mode,sys_student_assessment,sys_admission_learning_mode, sys_public_administration_category,sys_admission_category_code} = proxy.useDict('rxdrzt','sys_user_sex','marital_status','sys_student_qualification_status','sys_learning_mode','sys_student_assessment','sys_admission_learning_mode', 'sys_public_administration_category','sys_admission_category_code','test_format','sys_examinee_source_code','sys_student_admission_type');
// 新增导入结果相关变量
const resultDialogVisible = ref(false);
const importResult = ref({
  insertCount: 0,
  duplicateCount: 0,
  duplicateXh: []
});

// 状态管理
const importList = ref([]);
const nationList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const showAllColumns = ref(false); // 控制是否显示次要列
const activeSearchNames = ref([]); // 搜索区折叠状态
const excelDialogVisible = ref(false); // 导入对话框状态
// 添加证件类型列表
const certificateTypeList = ref([]);
const politicalStatusList = ref([]);//政治面貌

// 响应式数据 - 按实体类顺序排列所有字段
const data = reactive({
  form: {
    id: null,
    stuType: null,
    ksbh: null,
    xm: null,
    xh: null,
    zjlx: null,
    zjhm: null,
    csrq: null,
    mzm: null,
    xbm: null,
    hfm: null,
    xyjrm: null,
    zzmmm: null,
    hkszdm: null,
    hkszdxxdz: null,
    daszdw: null,
    daszdwdz: null,
    daszdwyzbm: null,
    kslym: null,
    bydwm: null,
    bydw: null,
    byzydm: null,
    byzymc: null,
    xxxs: null,
    xlm: null,
    xlzsbh: null,
    byny: null,
    zcxh: null,
    xwm: null,
    xwzsbh: null,
    lqdwdm: null,
    lqdwmc: null,
    lqzydm: null,
    lqzymc: null,
    zydmjmc: null,
    ksfsm: null,
    zxjh: null,
    lqlbm: null,
    dxwpdwszdm: null,
    dxwpdw: null,
    lqyxsm: null,
    xymc: null,
    xydmjmc: null,
    zzllm: null,
    zzllmc: null,
    wgym: null,
    wgymc: null,
    ywk1m: null,
    ywk1mc: null,
    ywk2m: null,
    ywk2mc: null,
    zzll: null,
    wgy: null,
    ywk1: null,
    ywk2: null,
    zf: null,
    fscj: null,
    zcjzsbf: null,
    zcj: null,
    js1mc: null,
    js1cj: null,
    js2mc: null,
    js2cj: null,
    blzgnx: null,
    pg: null,
    xszgzc: null,
    szssm: null,
    bz: null,
    lhpydwm: null,
    lhpydw: null,
    xzpx: null,
    xz: null,
    lqxxfs: null,
    rwqrxny: null,
    rwqgxssm: null,
    rwqgxdm: null,
    rwqgxmc: null,
    rwqxxxs: null,
    rwqzydm: null,
    rwqzymc: null,
    rwqxlzsbh: null,
    rwny: null,
    rwpzdw: null,
    tyny: null,
    typzdw: null,
    rwpzsbh: null,
    tcxyzbh: null,
    lqyjfxdm: null,
    lqyjfxmc: null,
    ggjhlb: null,
    txdz: null,
    lxfs: null,
    drzt: null,
    jyzt: null
  },
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    stuType: null,
    ksbh: null,
    xm: null,
    xh: null,
    zjlx: null,
    zjhm: null,
    csrq: null,
    mzm: null,
    xbm: null,
    zzmmm: null,
    bydw: null,
    lqzymc: null,
    byny: null,
    xszgzc: null,
    tcxyzbh: null,
    drzt: null,
  },
  rules: {},
  options: regionData,
  selectHuKouSuoZaiDi: []
});

const { queryParams, form, rules, options, selectHuKouSuoZaiDi } = toRefs(data);

/** 查询列表 */
function getList() {
  loading.value = true;
  listImport(queryParams.value).then(response => {
    importList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  }).catch(() => {
    loading.value = false;
  });
}

// 表单重置（清空所有字段）
function reset() {
  form.value = {
    id: null,
    stuType: null,
    ksbh: null,
    xm: null,
    xh: null,
    zjlx: null,
    zjhm: null,
    csrq: null,
    mzm: null,
    xbm: null,
    hfm: null,
    xyjrm: null,
    zzmmm: null,
    hkszdm: null,
    hkszdxxdz: null,
    daszdw: null,
    daszdwdz: null,
    daszdwyzbm: null,
    kslym: null,
    bydwm: null,
    bydw: null,
    byzydm: null,
    byzymc: null,
    xxxs: null,
    xlm: null,
    xlzsbh: null,
    byny: null,
    zcxh: null,
    xwm: null,
    xwzsbh: null,
    lqdwdm: null,
    lqdwmc: null,
    lqzydm: null,
    lqzymc: null,
    zydmjmc: null,
    ksfsm: null,
    zxjh: null,
    lqlbm: null,
    dxwpdwszdm: null,
    dxwpdw: null,
    lqyxsm: null,
    xymc: null,
    xydmjmc: null,
    zzllm: null,
    zzllmc: null,
    wgym: null,
    wgymc: null,
    ywk1m: null,
    ywk1mc: null,
    ywk2m: null,
    ywk2mc: null,
    zzll: null,
    wgy: null,
    ywk1: null,
    ywk2: null,
    zf: null,
    fscj: null,
    zcjzsbf: null,
    zcj: null,
    js1mc: null,
    js1cj: null,
    js2mc: null,
    js2cj: null,
    blzgnx: null,
    pg: null,
    xszgzc: null,
    szssm: null,
    bz: null,
    lhpydwm: null,
    lhpydw: null,
    xzpx: null,
    xz: null,
    lqxxfs: null,
    rwqrxny: null,
    rwqgxssm: null,
    rwqgxdm: null,
    rwqgxmc: null,
    rwqxxxs: null,
    rwqzydm: null,
    rwqzymc: null,
    rwqxlzsbh: null,
    rwny: null,
    rwpzdw: null,
    tyny: null,
    typzdw: null,
    rwpzsbh: null,
    tcxyzbh: null,
    lqyjfxdm: null,
    lqyjfxmc: null,
    ggjhlb: null,
    txdz: null,
    lxfs: null,
    drzt: null,
    jyzt: null
  };
  selectHuKouSuoZaiDi.value = [];
  proxy?.resetForm("importRef");
}

// 取消操作
function cancel() {
  open.value = false;
  reset();
}
// 添加获取政治面貌列表的函数
function getPoliticalStatuses() {
  listPoliticalstatus(loadAllParams).then(response => {
    politicalStatusList.value = response.rows;
  });
}
// 添加政治面貌格式化函数
const formatPoliticalStatus = (row) => {
  const politicalStatus = row.zzmmm;
  if (!politicalStatus) return "";
  const politicalStatusObj = politicalStatusList.value.find(item => item.politicalValue === politicalStatus);
  return politicalStatusObj ? politicalStatusObj.politicalLabel : politicalStatus;
}

// 格式化民族
const formatNation = (row) => {
  const nation = row.mzm;
  if (!nation) return "";
  const nationObj = nationList.value.find(item => item.nadictValue === nation);
  return nationObj ? nationObj.nadictLabel : nation;
};

// 格式化户口所在地
const formatHukouLocation = (row) => {
  const code = row.hkszdm;
  if (!code) return "";
  const provinceCode = code.substring(0, 2) + "0000";
  const cityCode = code.substring(0, 4) + "00";
  const province = codeToText[provinceCode] || "";
  const city = codeToText[cityCode] || "";
  const district = codeToText[code] || "";
  return [province, city, district].filter(Boolean).join(" ");
};


// 获取证件类型列表
function getCertificateTypes() {
  listGertificatetype(loadAllParams).then(response => {
    certificateTypeList.value = response.rows;
  });
}



// 格式化证件类型
const formatCertificateType = (row) => {
  const certType = row.zjlx;
  if (!certType) return "";
  const certTypeObj = certificateTypeList.value.find(item => item.cardtValue === certType);
  return certTypeObj ? certTypeObj.cardtLabel : certType; // 假设字典项有name字段
}

// 获取状态样式
const getStatusClass = computed(() => {
  return (status) => {
    switch(status) {
      case '1': // 假设1是成功状态
        return 'status-success';
      case '2': // 假设2是失败状态
        return 'status-error';
      case '3': // 假设3是待处理状态
        return 'status-warning';
      default:
        return 'status-default';
    }
  };
});

// 搜索/重置
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

function resetQuery() {
  proxy?.resetForm("queryRef");
  handleQuery();
}

// 获取民族列表
function getNationalities() {
  listNation(loadAllParams).then(response => {
    nationList.value = response.rows;
  });
}
// 复制重复学号到剪贴板
function copyDuplicateXh() {
  if (importResult.value.duplicateXh && importResult.value.duplicateXh.length) {
    const text = importResult.value.duplicateXh.join('\n');
    navigator.clipboard.writeText(text).then(() => {
      proxy?.$modal.msgSuccess('复制成功');
    }).catch(() => {
      proxy?.$modal.msgError('复制失败，请手动复制');
    });
  }
}
// 选择项变化
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id);
  single.value = selection.length !== 1;
  multiple.value = !selection.length;
}

/** 新增按钮操作 */
function handleAdd() {
  reset();
  open.value = true;
  title.value = "添加入学前学生信息";
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset();
  const _id = row?.id || ids.value[0];
  getImport(_id).then(response => {
    form.value = { ...response.data };
    // 回显户口所在地
    if (form.value.hkszdm) {
      selectHuKouSuoZaiDi.value = [
        form.value.hkszdm.substring(0, 2) + "0000",
        form.value.hkszdm.substring(0, 4) + "00",
        form.value.hkszdm
      ];
    }
    open.value = true;
    title.value = "修改入学前学生信息";
  });
}

// 提交表单
function submitForm() {
  proxy?.$refs["importRef"].validate(valid => {
    if (valid) {
      if (form.value.id) {
        updateImport(form.value).then(() => {
          proxy?.$modal.msgSuccess("修改成功");
          open.value = false;
          getList();
        });
      } else {
        addImport(form.value).then(() => {
          proxy?.$modal.msgSuccess("新增成功");
          open.value = false;
          getList();
        });
      }
    }
  });
}

// 删除操作
function handleDelete(row) {
  const _ids = row?.id || ids.value;
  proxy?.$modal.confirm(`是否确认删除编号为"${_ids}"的数据？`).then(() => {
    return delImport(_ids);
  }).then(() => {
    getList();
    proxy?.$modal.msgSuccess("删除成功");
  }).catch(() => {});
}

// 导出操作
function handleExport() {
  proxy?.download('student/import/export', { ...queryParams.value }, `import_${new Date().getTime()}.xlsx`);
}

// 导入相关
const uploadExcelUrl = ref(import.meta.env.VITE_APP_BASE_API + "/student/import/import");
const headers = ref({ Authorization: "Bearer " + getToken() });
const uploadRef = ref({});

function handleExcelImport() {
  excelDialogVisible.value = true;
}

function submitUpload() {
  uploadRef.value.submit();
}

const props = defineProps({
  modelValue: [String, Object, Array],
  fileSize: { type: Number, default: 2048 },
  fileType: { type: Array, default: () => ["xls", "xlsx"] },
});

function handleBeforeUpload(file) {
  let isExcel = false;
  if (props.fileType.length) {
    const fileExtension = file.name.split(".").pop() || "";
    isExcel = props.fileType.includes(fileExtension);
  }
  if (!isExcel) {
    proxy?.$modal.msgError(`请上传${props.fileType.join("/")}格式文件!`);
    return false;
  }
  if (file.size / 1024 / 1024 > props.fileSize) {
    proxy?.$modal.msgError(`文件大小不能超过${props.fileSize}MB!`);
    return false;
  }
  proxy?.$modal.loading("上传中，请稍候...");
  return true;
}

function handleUploadError() {
  proxy?.$modal.msgError("上传失败");
  uploadRef.value.clearFiles();
  proxy?.$modal.closeLoading();
}

// 修改上传成功处理方法
function handleUploadSuccess(res) {
  uploadRef.value.clearFiles();
  proxy?.$modal.closeLoading();

  if (res.code === 200) {
    // 保存导入结果数据
    importResult.value = {
      insertCount: res.insertCount || 0,
      duplicateCount: res.duplicateCount || 0,
      duplicateXh: res.duplicateXh || []
    };
    console.log(importResult.value)
    // 显示结果对话框
    resultDialogVisible.value = true;
    excelDialogVisible.value = false;
    getList();
  } else {
    proxy?.$modal.msgError(res.msg || "上传失败");
  }
}
// 户口所在地选择
function handleChangeHuKouSuoZaiDi() {
  form.value.hkszdm = selectHuKouSuoZaiDi.value[2] || "";
}

// 初始化
onMounted(() => {
  getNationalities();
  getCertificateTypes();
  getPoliticalStatuses();
  getList();
});

</script>

<style scoped>
.search-collapse {
  width: 100%;
  margin-top: 10px;
  border-top: 1px dashed #e5e7eb;
  padding-top: 10px;
}

.form-collapse {
  margin-top: 15px;
}

.mb8 {
  margin-bottom: 8px;
}

/* 表格样式优化 */
.table-hover-effect {
  transition: all 0.2s ease;
}

.table-hover-effect th {
  background-color: #f5f7fa;
  font-weight: 500;
  color: #4e5969;
}

.table-hover-effect tr:hover > td {
  background-color: #f0f7ff;
  transition: background-color 0.2s ease;
}

/* 按钮样式优化 */
.btn-hover-effect {
  transition: all 0.2s ease;
}

.btn-hover-effect:hover {
  transform: translateY(-2px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.btn-operation {
  transition: color 0.2s ease;
}

/* 对话框样式优化 */
.dialog-container {
  padding: 10px 0;
}

.form-scroll-container {
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 10px;
  scrollbar-width: thin;
  scrollbar-color: #c0c4cc #f5f7fa;
}

.form-scroll-container::-webkit-scrollbar {
  width: 6px;
}

.form-scroll-container::-webkit-scrollbar-track {
  background: #f5f7fa;
  border-radius: 3px;
}

.form-scroll-container::-webkit-scrollbar-thumb {
  background-color: #c0c4cc;
  border-radius: 3px;
}

/* 表单卡片样式 */
.form-card {
  margin-bottom: 20px;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  transition: all 0.3s ease;
}

.form-card:hover {
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  border-color: #dcdfe6;
}

.card-header {
  display: flex;
  align-items: center;
  color: #1f2329;
  font-weight: 500;
  font-size: 14px;
}

.card-title {
  margin-left: 8px;
}

/* 表单布局 */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  padding: 10px 0;
}

.form-item {
  margin-bottom: 0 !important;
}

.full-width {
  grid-column: 1 / -1;
}

.form-control {
  width: 100% !important;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.form-control:focus {
  border-color: #409eff !important;
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2) !important;
}

/* 对话框按钮样式 */
.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.btn-primary {
  transition: all 0.2s ease;
}

.btn-primary:hover {
  background-color: #409eff !important;
  transform: translateY(-1px);
}

.btn-secondary {
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background-color: #f5f7fa !important;
  transform: translateY(-1px);
}

/* 状态标签样式 */
.status-success {
  color: #67c23a;
  background-color: #f0f9eb;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.status-error {
  color: #f56c6c;
  background-color: #fef0f0;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.status-warning {
  color: #e6a23c;
  background-color: #fdf6ec;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}

.status-default {
  color: #909399;
  background-color: #f4f4f5;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
}

/* 响应式调整 */
@media (max-width: 768px) {
  .form-grid {
    grid-template-columns: 1fr;
  }

  .full-width {
    grid-column: 1;
  }
}

:deep(.el-collapse-item__content) {
  padding-bottom: 10px !important;
}

:deep(.el-dialog__body) {
  padding: 15px 20px !important;
}
/* 重复学号展示优化样式 */
.duplicate-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.copy-btn {
  color: #409eff;
  padding: 0;
  height: auto;
}

.copy-btn:hover {
  color: #66b1ff;
}

.duplicate-tags-container {
  max-height: 200px;
  overflow-y: auto;
  padding: 10px;
  background-color: #f8f9fa;
  border-radius: 4px;
  border: 1px solid #e9ecef;
  scrollbar-width: thin;
}

.duplicate-tags-container::-webkit-scrollbar {
  width: 6px;
}

.duplicate-tags-container::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.duplicate-tags-container::-webkit-scrollbar-thumb {
  background: #c0c4cc;
  border-radius: 3px;
}

.duplicate-tag {
  margin: 0 8px 8px 0;
  padding: 4px 10px;
  font-size: 13px;
  line-height: 1.5;
  border-radius: 4px;
}
</style>
